from .models import Log
from django.utils import timezone

class LogService:
    @staticmethod
    def log_login(user):
        """
        记录用户登录日志
        """
        Log.objects.create(
            user=user,
            action="login",
            related_object="Login",
            timestamp=timezone.now(),
            log_type="INFO",  # 可以根据需要指定日志类型
            additional_data={"login_method": "API"}  # 附加数据，如果需要的话
        )

    @staticmethod
    def log_action(user, action, log_type="INFO", related_object=None, additional_data=None):
        """
        记录通用操作日志
        """
        Log.objects.create(
            user=user,
            action=action,
            related_object=related_object,
            timestamp=timezone.now(),
            log_type=log_type,
            additional_data=additional_data
        )
